<?php
/**
* the main file of the ACP
*
* This is the only file in the ACP that is called directly, every other file is called through this one.
*  It sets up the ACP by including the configuration files and the general functions.  It also calls 
* modules by implementing the urlFinder
*@author		wil hamilton <wil.hamilton@gmail.com>
*@license		bsd
*@version		0.5
*@package		core
* @todo 		finish commenting, update URL finder section to include a module defined in by the user instead of jus tthe main module
 */

session_start();
ob_start();
 
 error_reporting(E_ERROR);
 
#include the required configuration file
require('../config.php');
include(ROOT . 'plugins/config.php');

#include the general functions, (required for operation)
if(!include(ROOT . 'core/general.functions.php'))
{
	throw new Exception("Fatal Error: Could not include general functions.");
}

if($user = user::isAdmin())
{
	
	#get the current URL, pass it to the urlFinder class, which then includes the appropriate file
	$urlParts = USE_PATH_INFO ? (array_key_exists('PATH_INFO', $_SERVER) ? $_SERVER['PATH_INFO'] : '') : $_SERVER['argv'][0];		//get the url 
	$urlParts = array_values(array_filter(explode('/', $urlParts)));																//puts the url into an array

	#looks for the url relation in the db, then calls the appropriate file
	#this is where teh magic takes place lulz
	if(count($urlParts) > 0)
	{
		moduleLoader::getACP($urlParts);
	}
	else
	{
		moduleLoader::getACP(array('acp'));
	}
	
}
else
{
	header("Location:  " . ROOT_URL . URL_BASE  . "user/login/admin");
}
?>